/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.gob.dirpen.dao.impl;

import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import pe.gob.dirpen.dao.AnioDAO;
import pe.gob.dirpen.entities.GenmaAnio;

/**
 *
 * @author DINA
 */
@Repository
public class AnioDAOImpl  extends HibernateDaoSupport implements AnioDAO{

    private static final Logger logger = Logger.getLogger(AnioDAOImpl.class);

    @Autowired
    public AnioDAOImpl(SessionFactory sessionFactory){
          setHibernateTemplate( new HibernateTemplate(sessionFactory));
    }

    @Override
    public List<GenmaAnio> buscarAnios(GenmaAnio anio) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GenmaAnio.class);
        /*if( !Utiles.nullToBlank( anio.get ).equals("")){
                criteria.add( Restrictions.eq("familiaproductos.famcodigopk", material.getFamiliaproductos().getFamcodigopk() ) );
        }      */
        return getHibernateTemplate().findByCriteria(criteria);
    }

    @Override
    public void registrarAnio(GenmaAnio anio) {
         this.getHibernateTemplate().saveOrUpdate(anio);
    }

    @Override
    public GenmaAnio obtenerAnio(int anio) {
        Query query = getSession().createQuery(" from GenmaAnio m where m.nanioIdentificador = :id ")
        .setInteger("id", anio);
        return (GenmaAnio) query.uniqueResult();
    }

}
